﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="~/plugins/mzui/js/mzui.min.js"></script>
    <link href="~/plugins/mzui/css/mzui.min.css" rel="stylesheet" />
    <title>我的消费</title>
</head>
<body class="with-nav-bottom">
    <table class="table bordered white">
        <thead>
            <tr class="purple-pale">
                <th>订单/消费商家</th>
                <th>折扣价</th>
                <th>原价</th>
            </tr>
        </thead>
        <tbody id="tbody">
            <script id="tpl" type="text/html">
                {{each list as item index}}
                <tr>
                    <td>{{item.order_no}}</td>
                    <td>{{item.rmb}}</td>
                    <td>{{item.amount}}</td>
                </tr>
                <tr>
                    <td>{{item.name}}</td>
                    <td colspan="2">{{item.addtime}}</td>
                </tr>
                <tr>
                    <td colspan="3" class="text-center primary-pale text-red">{{# item.zhekou}}</td>
                </tr>
                <tr>
                    <td id="{{item.gid}}" onclick="wxpay('{{item.gid}}');" colspan="3" class="text-center primary text-red">去支付</td>
                </tr>
                {{/each}}
            </script>
        </tbody>
        <tfoot>
            <tr>
                <th colspan="4" id="nextpage" class="title text-center" onclick="getlist(document.getElementById('pageindex').innerHTML);">显示更多 <i class="icon icon-double-angle-down"></i></th>
            </tr>
        </tfoot>
    </table>
    <div id="ss" class="affix dock-bottom modal hidden">
        <div class="section box">
            <div class="control has-success">
                <input name="lx" type="text" class="input" value="0">
            </div>
        </div>
    </div>
    <nav class="nav affix dock-bottom justified">
        <a href="/home/index">商城</a>
        <a href="/user/grzx" class="active text-info">我的</a>
    </nav>
    <label id="pageindex" class="hidden">0</label><label id="pages" class="hidden">1</label>
    <label id="Controllers" class="hidden">/user/orderlist</label>
    <script src="~/js/jquery.js"></script>
    <script src="~/js/template-web.js"></script>
    <script src="~/js/mlist.js"></script>
    <script>
        function wxpay(gid) {
            $.ajax({
                url: "/ajax/api.ashx",
                data: "ff=wxpay&gid=" + gid + "&Cache=" + Math.random(),
                type: "post",
                cache: false,
                timeout: 8000,
                dataType: "json",
                ContentType: "application/json; charset=utf-8",
                async: false,//一定要是同步请求，否则会跳转；（ajax默认是异步的）
                error: function () { document.getElementById(gid).innerText = "去支付"; document.getElementById(gid).removeAttribute("disabled"); alert("AJAX Error"); },
                beforeSend: function () { document.getElementById(gid).innerText = "微信支付中..."; document.getElementById(gid).setAttribute("disabled", true); },
                success: function (data) {
                    document.getElementById(gid).innerText = "去支付";
                    document.getElementById(gid).removeAttribute("disabled");
                    if (data.appId != "payerr") {
                        WeixinJSBridge.invoke('getBrandWCPayRequest', data, function (res) {
                            switch (res.err_msg) {
                                case "get_brand_wcpay_request:ok":
                                    self.location = "/home/msg?url=/user/wddd&msg=支付成功";
                                    break;
                                case "get_brand_wcpay_request:cancel":
                                    alert("你取消了支付,请让商家重新给你发送账单!");
                                    break;
                                default:
                                    alert("支付失败,请让商家重新给你发送账单!");
                                    break;
                            }
                        });
                    }
                    else
                    { alert(data.return_msg);}
                },
            });
        }
    </script>
</body>
</html>